package com.feihao.zhou.demo02_Map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class TestHashMapTeacher {
    public static void main(String[] args) {
        Teacher teacher1 = new Teacher("张三",13);
        Teacher teacher2 = new Teacher("李四",17);
        Teacher teacher3 = new Teacher("王五",18);
        Teacher teacher4 = new Teacher("宅六",15);


        HashMap<Teacher,String> map= new HashMap<>();
        map.put(teacher1,"江西");
        map.put(teacher3,"广东");
        map.put(teacher2,"湖南");
        map.put(teacher4,"北京");
        System.out.println("---------keyset方式----------------");


        //遍历map集合：1
        Set<Teacher> key = map.keySet();
        for (Teacher k : key) {
            String value = map.get(k);
            System.out.println(k + "----" + value);
        }

        //遍历map集合：2
        System.out.println("---------entryset方式----------------");


        Set<Map.Entry<Teacher, String>> entries = map.entrySet();
        for (Map.Entry<Teacher, String> entry : entries) {
            Teacher key1 = entry.getKey();
            String value = entry.getValue();
            System.out.println(key1 + "-----" + value);
        }

        System.out.println("---------lambda表达式遍历----------------");
        //遍历map集合：3

        map.forEach(new BiConsumer<Teacher, String>() {
            @Override
            public void accept(Teacher teacher, String s) {
                System.out.println(teacher + "----" + s);
            }
        });
//        keySetBL(map);


    }

    /**
     *
     * @param map
     */
    public static void keySetBL(HashMap<Teacher, String> map) {
        //再次使用：
        Set<Teacher> keySet = map.keySet();
        for (Teacher teacher : keySet) {
            String value = map.get(teacher);
            System.out.println(teacher + value);
        }
    }

    /**
     *
     * @param map
     */
    public static void entrySetBL(HashMap<Teacher,String> map){
        Set<Map.Entry<Teacher, String>> entries = map.entrySet();
        for (Map.Entry<Teacher, String> entry : entries) {
            Teacher key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "=" + value);
        }
    }


}
